package com.myrslok.util;

import com.myrslok.set.SourceTargetResource;
import org.jetbrains.annotations.NotNull;

import java.io.File;

public class FileResource implements SourceTargetResource<File, File> {

    private File sourceFile;
    private File targetFile;

    public FileResource(@NotNull final File sourceFile) {
        this.sourceFile = sourceFile;
        this.targetFile = sourceFile;
    }

    public FileResource(@NotNull final File sourceFile, @NotNull final File targetFile) {
        this.sourceFile = sourceFile;
        this.targetFile = targetFile;
    }

    public FileResource(final String sourceFile, final String targetFile) {
        this(new File(sourceFile), new File(targetFile));
    }

    public File getSource() {
        return sourceFile;
    }

    public File getTarget() {
        return targetFile;
    }

    @SuppressWarnings({"ControlFlowStatementWithoutBraces", "RedundantIfStatement"})
    @Override
    public boolean equals(final Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final FileResource that = (FileResource) o;

        if (sourceFile != null ? !sourceFile.equals(that.sourceFile) : that.sourceFile != null) return false;
        if (targetFile != null ? !targetFile.equals(that.targetFile) : that.targetFile != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = sourceFile != null ? sourceFile.hashCode() : 0;
        result = 31 * result + (targetFile != null ? targetFile.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "FileResource{" +
                "sourceFile=" + sourceFile +
                ", targetFile=" + targetFile +
                '}';
    }

}
